package Lee_code;

import java.util.HashSet;

public class Lee_36 {
    int row, column;
    public static boolean judge_column (char[][] board, int column)
    {
        HashSet<Character> set2 = new HashSet<>();
        for(int i=0; i<9; i++)
        {
            if(board[i][column]!='.') {
                if (!set2.contains(board[i][column])) {
                    set2.add(board[i][column]);
                } else {
                    return false;
                }
            }
        }
        return true;
    }
    public static boolean judge_row (char[][] board, int row)
    {
        HashSet<Character> set = new HashSet<>();
        for(int i=0; i<9; i++)
        {
            if(board[row][i]!='.') {
                if (!set.contains(board[row][i])) {
                    set.add(board[row][i]);
                } else {
                    return false;
                }
            }
        }
        return true;
    }
    public static boolean judge_3 (char[][] board, int row, int column)
    {
        HashSet<Character> set3 = new HashSet<>();
        for(int i=0; i<3; i++)
        {
            for(int j=0; j<3; j++)
            {
                if(board[i][j]!='.') {
                    if (!set3.contains(board[i][j])) {
                        set3.add(board[i][j]);
                    } else {
                        return false;
                    }
                }
            }

        }
        return true;
    }
    public boolean isValidSudoku(char[][] board) {
        row = 9;
        column = 9;
        for(int i=0; i<9; i++)
        {
            if(!judge_row(board, i)||!judge_column(board, i))
            {
                return false;
            }
        }
        for(int i=0; i<9; i=i+3)
        {
            for(int j=0; j<9; j=j+3)
            {
                if(!judge_3(board, i, j))
                {
                    return false;
                }
            }
        }
        return true;
    }
    public static void main(String[] args) {


    }
}
